// pages/99/99.js
const { Tab, extend } = require('../../dist/index');
var app=getApp();
Page(extend({}, Tab,{

  /**
   * 页面的初始数据
   */
  data: {
    sort_method: {
      list: [{
        id: 'hot',
        name: '销量'
      }, {
        id: 'new',
        name: '最新'
      }, {
        id: 'low',
        name: '券额'
      }, {
        id: 'price',
        name: '价格'
      }],
      selectedId: 'hot'
    }, 
    couponList: [],
    selectCategory: "",
    sorts: "hot",
    types: "jiu",
    picWidth: wx.getSystemInfoSync().windowWidth,
    pageIndex: 1,
    isLoading:true,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  var that=this
  that.setData({
    cate_method:wx.getStorageSync("menu_cate"),
    //is_kouling: app.globalData.is_kouling,
  })
  this.getMoreCouponList();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },


  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  //取商品
  getMoreCouponList: function () {
    var that = this
    wx.request({
      url: app.globalData.apiurl + "/Home/Item/getItems",
      dataType: 'json',
      data: {
        "type": that.data.types,
        "sort": that.data.sorts,
        "p": that.data.pageIndex,
        "size": 10,
        "cid": that.data.selectCategory
      },
      success: function (resRequest) {
        // console.log(resRequest.data.data.result);      
        if (resRequest.statusCode === 200) {
          if (resRequest.data.status == "0") {
            that.setData({
              couponList: that.data.couponList.concat(resRequest.data.data.items_list),
              isLoading: false
            })
          } else {
            that.setData({
              isLoading: true,
              loadOver: true
            })
          }
        }
      }
    });
  },
  handleZanTabChange(e) {
    var componentId = e.componentId;
    var selectedId = e.selectedId;
    if (componentId === "cate_method") {
      this.setData({
        selectCategory: selectedId
      })
    }
    if (componentId === "sort_method") {
      this.setData({
        sorts: selectedId
      })
    }
    this.setData({
      [`${componentId}.selectedId`]: selectedId,
      isLoading: true,
      couponList: [],
      pageIndex: 1,
    });
    this.getMoreCouponList()
  },
  onPullDownRefresh: function () {
    this.setData({
      couponList: [],
      isLoading: true,
      pageIndex: 1
    })
    wx.stopPullDownRefresh()
    this.getMoreCouponList()
  },
  onReachBottom: function () {
    this.setData({
      isLoading: true,
      pageIndex: this.data.pageIndex + 1
    })
    this.getMoreCouponList()
  },

}))